/**
 *所有非直冲用js
 */
function switchTab(switchradio, switchid, switchtext){
    $(switchid).innerHTML = switchtext;
    var pay_switches = $("pay_switch").getElementsByTagName("li");
    for (var i = 0; i < pay_switches.length; i++) {
        if (pay_switches[i].className == "selected") {
            pay_switches[i].className = "";
        }
    }
    var tab_li = switchradio.parentNode;
	switchradio.firstChild.checked = true;
    tab_li.className = "selected";
}

function chkPayway(paywayRadio){
    if (paywayRadio.value == "1") {
        $("pay_for_friends").style.display = 'block';
        (function(){
            if (typeof(autoSug) == "undefined") {
                autoSug = new autoSuggest("pay_input", {});
            }
        })();
    } else if (paywayRadio.value == "0") {
        $("pay_for_friends").style.display = 'none';
    }
}

function checkRate(input){
    var re = /^[0-9,]*$/;
    return re.test(input);
}




function showMobileRetry(){
    JQ("#retry").show();
    JQ("#progressBar").hide();
    JQ("#loadingTip").hide();
    JQ("#warning-msg").hide();
    JQ("#dialog_buttons").show();
    
    JQ("#retry").html('<div class="warn-smile">充值时间过长，请查看校内豆余额</div><p><span class="cgray">若充值不成功，请拨打</span>客服电话：010-84481818-1572</p>');
    
}

/*重试*/
function mobileRetryAction(){
    var params = JQ('#pay_form').serialize();
    var kxd_ye = Number($('kxd_ye').innerHTML);
    runProgress(60);
    JQ.ajax({
        type: "POST",
        url: "p0.txt",
        timeout: 60000,
        data: params,
        success: function(msg){
            alert("已完成充值！");
            window.location.href = '';
        }
    });
    
}

/*选择其他银行*/
function chooseOtherBank(e){
    if (JQ('#bankList').css('display') == 'none') {
        JQ('#bankList').slideDown('fast');
        JQ('.obank-txt a').html("- 其他银行");
    } else {
        JQ('#bankList').slideUp('fast');
        JQ('.obank-txt a').html("+ 其他银行");
    }
}



/**
 * 检测手机冲值的手机号码
 * @param {String} number
 * ＠return null
 */
function ajaxCheckMobile(number){
    var THIS = this;
    var tip = JQ("#ptip");
    var err = checkFormNumber(number);
    THIS.error = function(){
        tip.addClass("icon-incorrect");
        JQ("#nextStep").attr("disabled", "disabled");
        JQ("#nextStep").addClass("gray");
    }
    if (err.length > 0) {
        tip.html(err);
        THIS.error();
        return;
    }
    //错误信息
    this.lang = {
        RIGHT: '填写正确,请点击下一步',
        SYSTEM_ERROR: ' 订单失败，系统错误，请稍候再试',
        DOU_ERROR: '订单失败，充值数量错误，请核对后再试',
        LEVEL_ERROR:'订单失败，每天限充值两次，请改天再试！',
        LEVEL_ERROR2: "订单失败，您现在的用户级别暂时无法充值！",
        TIMES_ERROR: "订单失败，您的尝试次数过多，请改天再试",
        UNKNOWN_ERROR: "订单失败，系统错误，请稍候再试"
    }
    var params = JQ('#pay_form').serialize();
    tip.addClass("loading-data");
    JQ.ajax({
        type: "POST",
        url: "/ajax/umpajax.do",
        timeout: 120000,
        data: params,
        success: function(o){
            tip.removeClass("loading-data");
            tip.removeClass("icon-correct");
            if (o == "correct") {
                tip.removeClass("icon-incorrect");
                tip.html(THIS.lang.RIGHT);
                JQ("#orderNumber").val(o);
                enableNextButton();
                return;
            } else if (o == 9) {
                tip.html(THIS.lang.SYSTEM_ERROR);
            } else if (o == 8) {
                tip.html(THIS.lang.DOU_ERROR);
            } else if (o == 5) {
                tip.html(THIS.lang.LEVEL_ERROR);
            } else if (o == 6) {
                tip.html(THIS.lang.LEVEL_ERROR2);
            } else if (o == 7) {
                tip.html(THIS.lang.TIMES_ERROR);
            } else {
                tip.html(THIS.lang.UNKNOWN_ERROR);
            }
            THIS.error();
        },
        error: function(){
            PAY.Do.alert('错误提示', '出错了，可能网络发生故障，请稍候再试.');
        }
    });
}

/**
 * 使按钮可用
 */
function enableNextButton(){
    JQ("#ptip").addClass("icon-correct");
    JQ("#nextStep").removeAttr("disabled", "disabled");
    JQ("#nextStep").removeClass("gray");
    JQ("#nextStep").click(function(){
        getUmp();
    })
}

/**
 * 手机直冲的入口 初始化函数
 */
function f(){
    JQ("#nextStep").attr("disabled", "disabled");
    this.o = JQ("#mobile").val().trim();
    if (this.o.length == 11) {
        ajaxCheckMobile(this.o);
    }
    
}
/**
 * 7777手机话费
 */
function getUmp(){
    var params = JQ('#pay_form').serialize();
    PAY.Dom.disable();
    PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t1">icon</i><h3>请你在新打开的页面上完成充值!</h3><div>充值完成前请不要关闭此窗口</div><p>如果充值过程遇到问题,请联系客服寻求帮助。客服:010-84481818-1572</p></div>', "已完成充值", "充值遇到问题");
    PAY.Event.addEvent($("close_btn"), "click", function(){
        window.location.reload();
    });
    $("pay_n_btn").onclick = function(){
        window.location = "http://pay.renren.com/help/index.do";
    }
    //$("pay_form").action = "/request/ump.do";
    window.open('', 'payWin');
    $("pay_form").submit();
}

/**
 * mop一卡通
 */
function getMopykt(){
    var reg = /^\d{10,16}$/;
    if (JQ('#kname').val() == '' || JQ('#kpass').val() == '') {
        PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>猫扑一卡通卡号、密码不能为空，请核对后重新输入<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
        return;
    }
    if (!reg.test(JQ('#kname').val())) {
        PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>卡号、密码格式不对，请核对后重新输入<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
        return;
    }
    if (JQ('#pay_input_vericode').val() == '') {
        PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>验证码不能为空，请核对后重新输入<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
        return;
    }
    var mm = JQ("input[@type=radio][@name=money][@checked]").val();
    var msg = '<div id="retry"></div><div class="loading-bar"><div class="progress-bar" id="progressBar"><div class="l"></div><div class="m" id="progress"></div><div class="r"></div></div></div><div class="loading-tip" id="loadingTip">充值进行中，请耐心等待！<span class="gray">充值成功后，本窗口将自动关闭。</span></div><div class="warning-msg" id="warning-msg"><b>请等待窗口自动关闭，若强行关闭，有可能造成订单失败！</b></div>';
    PAY.Do.alert("温馨提示", msg, null, null, false, true);
    PAY.Dom.disable();
    runProgress(40);
    var params = JQ('#pay_form').serialize();
    var kxd_ye = Number($('kxd_ye').innerHTML);
    JQ.ajax({
        type: "POST",
        url: "/request/mopykt.do",
        timeout: 40000,
        data: params,
        success: function(o){
            if (o > 0) {
                PAY.Do.alert("充值成功", "<div class='direct-pay-dialog'><i class='t1'>icon</i><h3 class='success'>充值成功!</h3><p>请查看您的<a href='http://pay.renren.com/pay/index.do'>充值记录</a></p></div>");
                $('kxd_ye').innerHTML = (kxd_ye + Number(o));
            } else if (o == 'errcard' || o == 'error') {
                PAY.Do.alert("错误提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>订单失败，请核对您的卡号和密码，稍候再试。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
            } else if (o == 'used') {
                PAY.Do.alert("错误提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>订单失败，此卡已经被使用过，请核对后稍候再试。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
            } else if (o == 'errcode') {
                PAY.Do.alert("错误提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>订单失败，验证码不一致，稍候再试。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
            } else {
                PAY.Do.alert("错误提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>订单失败，系统错误，请稍候再试。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
            }
            newverifypic();
            clearInterval(intval);
        },
        error: function(){
            PAY.Do.alert('错误提示', '出错了，可能网络发生故障，请稍候再试...');
        }
    });
}


/*神州行*/
function must_wait(){
    var reg = /^\d{10,17}$/;
    var pass = /^\d{8,18}$/;
    
    if (!reg.test(JQ('#kname').val()) || !pass.test(JQ('#kpass').val())) {
        PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>请输入充值卡卡号和密码<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
        return;
    }
    var mm = JQ("input[@type=radio][@name=money][@checked]").val();
    if (mm == "" || typeof(mm) == 'undefined') {
        PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>请先选择充值卡面额<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
        return;
    }
    if ($('pay_payway_2').checked && $('friend_id').value == "") {
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请输入你的好友姓名。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
    }
    
    var msg = '<div id="retry"></div><div class="loading-bar"><div class="progress-bar" id="progressBar"><div class="l"></div><div class="m" id="progress"></div><div class="r"></div></div></div><div class="loading-tip" id="loadingTip">充值进行中，请耐心等待！<span class="gray">充值成功后，本窗口将自动关闭。</span></div><div class="warning-msg" id="warning-msg"><b>请等待窗口自动关闭，若强行关闭，有可能造成充值失败！</b></div>';
    PAY.Do.alert("温馨提示", msg, null, null, false, true);
    PAY.Dom.disable();
    runProgress(120);
    var params = JQ('#pay_form').serialize();
    //var k = JQ("input[name='money']:checked").val();	
    var kxd_ye = Number($('kxd_ye').innerHTML);
    JQ.ajax({
        type: "POST",
        url: "/request/szx.do",
        timeout: 120000,
        data: params,
        success: function(o){
            if (o > 0) {
                PAY.Do.alert("充值成功", "<p class='cred'><b>充值成功，请查看您的<a href='http://pay.renren.com/pay/index.do'>校内账户</a>！</b></p>");
                $('kxd_ye').innerHTML = (kxd_ye + Number(o));
            } else if (o == 'errcard') {
                PAY.Do.alert("错误提示", '<div class="direct-pay-dialog"><i class="t2">icon</i><h3>充值失败!</h3><p>错误的卡号或者密码！<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>');
                
            }
            clearInterval(intval);
        },
        error: function(){
            PAY.Do.alert('错误提示', '出错了，可能网络发生故障，请稍候再试...');
        }
    });
}

//短信
function checkMobile(){
    var mobile = document.form1.mobile.value;
    var reg0 = /^1\d{10}$/;
    if (!reg0.test(mobile)) {
        document.form1.mobile.value = '';
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请输入正确的手机号码。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
        document.form1.mobile.focus();
        return false;
    } else {
        //document.form1.action="/request/sms.do";
        document.form1.submit();
    }
}

//固定电话
function checkTel(){
    var tel = document.form1.tel.value;
    var reg0 = /^\d{8,12}$/;
    if (!reg0.test(tel)) {
        document.form1.tel.value = '';
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请输入固定电话的号码（带区号）。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
        document.form1.tel.focus();
        return false;
    } else {
        //document.form1.action="/request/sms.do";
        document.form1.submit();
    }
}

//银行卡
function checkPay(){
    if ($('pay_payway_2').checked && $('friend_id').value == "") {
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请输入你的好友姓名。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
    }
    if ($('pay_paynum_10').checked && $('pay_paynum_10_i').value == "") {
        PAY.Do.alert("错误提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>自定义金额不能为空<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
    }
    PAY.Dom.disable();
    PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t1">icon</i><h3>请你在新打开的页面上完成充值!</h3><div>充值完成前请不要关闭此窗口</div><p>如果充值过程遇到问题,请联系客服寻求帮助。客服:010-84481818-1572</p></div>', "已完成充值", "充值遇到问题");
    PAY.Event.addEvent($("close_btn"), "click", function(){
        if (PAY.Dom.disabled) {
            PAY.Dom.enable();
        }
    });
    $("pay_n_btn").onclick = function(){
		 window.open('http://pay.renren.com/help/index.do', 'payWin');
       }
    $("pay_form").submit();
}


//UNION Soo PAY
function checkSooPay(){
    var otherNum = document.getElementById("pay_paynum_10");
    if ($('pay_payway_2').checked && $('friend_id').value == "") {
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请输入你的好友姓名。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
    }
    var mobileNum = $("mobile").value.replace(/\s/g, "");
    //其他开心豆数量的空值提示
    if (otherNum.checked == true) {
        var kxdNum = otherNum.value;
        if (kxdNum == "" || isNaN(kxdNum) || kxdNum == 0) {
            PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>请正确填写校内豆的数量。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
            return false;
            PAY.Event.addEvent($("close_btn"), "click", function(){
                PAY.Dom.enable();
            });
            setTimeout(function(){
                $("p_close_link").onclick = function(){
                    $("pay_dialog").style.display = "none";
                    PAY.Dom.enable();
                }
            }, 10);
            return false;
        }
    }
    if (isNaN(mobileNum) || mobileNum == "" || mobileNum.length != 11) {
        PAY.Do.alert("温馨提示", "<div class='direct-pay-dialog'><i class='t2'>icon</i><h3>充值失败!</h3><p>没有正确填写手机号码。<br />如有疑问,请您联系客服寻求帮助。客服:010-84481818-1572</p></div>");
        return false;
        PAY.Event.addEvent($("close_btn"), "click", function(){
            PAY.Dom.enable();
        });
        setTimeout(function(){
            $("p_close_link").onclick = function(){
                $("pay_dialog").style.display = "none";
                PAY.Dom.enable();
            }
        }, 10);
        return false;
    }
    PAY.Dom.disable();
    PAY.Do.alert("温馨提示", '<div class="direct-pay-dialog"><i class="t1">icon</i><h3>请你在新打开的页面上完成充值!</h3><div>充值完成前请不要关闭此窗口</div><p>如果充值过程遇到问题,请联系客服寻求帮助。客服:010-84481818-1572</p></div>', "已完成充值", "充值遇到问题");
    PAY.Event.addEvent($("close_btn"), "click", function(){
        PAY.Dom.enable();
    });
    setTimeout(function(){
        $("p_close_link").onclick = function(){
            $("pay_dialog").style.display = "none";
            PAY.Dom.enable();
        }
    }, 10);
    $("pay_n_btn").onclick = function(){
        window.location = "http://pay.renren.com/help/index.do";
    }
    window.open('', 'payWin');
    $("pay_form").submit();
}
